package keyboard.controller;

import keyboard.entity.Notes;
import keyboard.exception.ClientException;
import keyboard.service.NotesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 2B键盘
 * @version 1.0
 * @create: 2018-05-07 12:42
 * @desc 笔记
 **/
@Controller
@RequestMapping("/notes")
public class NotesController{

    @Autowired
    NotesService notesService;

    /**
     * 修改笔记,通过id查询出笔记,返回到前台
     * @param id
     * @return
     */
    @RequestMapping("/toEdit.do")
    public String editNotes(Integer id, Model model) throws ClientException {
        if(id <= 0 || id == null){
            throw new ClientException("未获取到笔记id");
        }
        Notes notes = notesService.QueryNotesById(id);
        model.addAttribute("notes",notes);
        return "/notesList/edit";
    }

}
